//
//  PartyServiceContactViewController.m
//  ShangHaiHuDongApp
//
//  Created by 刘应平 on 2017/7/4.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "PartyServiceContactViewController.h"
#import "LPCostomLabelAndTextViewAdaptHeightView.h"
#import "LPCostomLabelAndTextFieldAndImageView.h"
@interface PartyServiceContactViewController ()
/** 电话  */
@property (strong, nonatomic) LPCostomLabelAndTextFieldAndImageView  *phoneNumber;
/**  提交  */
@property (strong, nonatomic) UIButton  *sendButton;
/**  scrollView  */
@property (strong, nonatomic) UIScrollView  *backScrollView;


/**  留言  */
@property (strong, nonatomic) LPCostomLabelAndTextViewAdaptHeightView  *beizhu;
@end

@implementation PartyServiceContactViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.titlelabel.text = @"联系留言";
    [self.view addSubview:self.backScrollView];
    [self.backScrollView addSubview:self.beizhu];
    [self.backScrollView addSubview:self.phoneNumber];
    [self.backScrollView addSubview:self.sendButton];
    
    self.backScrollView.contentSize = CGSizeMake(self.view.width, self.sendButton.bottom + 65 * [UIScreen zj_screenHScale]);
}


- (void)clickButton{
    __weak typeof(self) weakSelf = self;
    if (![CManager zj_validateMobile:self.phoneNumber.secondTextField.text]) {
        [YJProgressHUD showMessage:@"请输入正确的联系电话" inView:self.view];
        [self.phoneNumber.secondTextField becomeFirstResponder];
        return;
    }
    
    if (self.beizhu.adaptTextView.text.length == 0) {
         [YJProgressHUD showMessage:@"请输入留言" inView:self.view];
        [self.beizhu.adaptTextView becomeFirstResponder];
        return;
    }
    
    NSMutableDictionary *paramer = [NSMutableDictionary dictionary];
    paramer[@"MOBILE"] = self.phoneNumber.secondTextField.text;
    paramer[@"MSG"] = self.beizhu.adaptTextView.text;
    paramer[@"ACCOUNT_ID"] = ZJUSERINFORMODEL.ORG_ACCOUNT.ID;
    paramer[@"DEPT_ID"] = self.model.ID;
    [YJProgressHUD showMessage:@"提交中..." duration:10 view:self.view];
    
    [NetWorkingManager postWithUrlString:[NetWorkingURL getorgmsgCenterMsgsendMsg] Parameter:paramer Success:^(id object) {
        NetWorkModel *model = [NetWorkModel yy_modelWithJSON:object];
        if ([model.STATE isEqualToString:@"20000"]) {
            [YJProgressHUD showMsgWithoutView:@"提交成功"];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.7 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [weakSelf.navigationController popViewControllerAnimated:YES];
            });
            
        }else{
            [YJProgressHUD showMsgWithoutView:@"提交失败"];
        }
    } Fail:^(id object) {
        [YJProgressHUD showMsgWithoutView:@"提交失败"];
    }];

}


- (LPCostomLabelAndTextFieldAndImageView *)phoneNumber{
    if (!_phoneNumber) {
        _phoneNumber = [[LPCostomLabelAndTextFieldAndImageView alloc] initWithFrame:CGRectMake(0, self.beizhu.bottom + 30 * [UIScreen zj_screenHScale], self.view.width, 80 * [UIScreen zj_screenHScale]) title:@"联系电话" placehold:@"请输入联系电话" imageString:@""];
        _phoneNumber.isShow = NO;
        _phoneNumber.secondTextField.text = ZJUSERINFORMODEL.ORG_ACCOUNT.MOBILE;
        _phoneNumber.secondTextField.userInteractionEnabled = YES;
        _phoneNumber.secondTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
        _phoneNumber.maxNumber = 11;
    }
    return _phoneNumber;
}


- (LPCostomLabelAndTextViewAdaptHeightView *)beizhu{
    if (_beizhu == nil) {
        _beizhu = [[LPCostomLabelAndTextViewAdaptHeightView alloc] initWithFrame:CGRectMake(0,  20 * [UIScreen zj_screenHScale], self.view.width, 200 * [UIScreen zj_screenHScale]) title:@"留言 :" textViewHeight:160 * [UIScreen zj_screenHScale]];
        _beizhu.maxNumber = 200;
    }
    return _beizhu;
}


- (UIButton *)sendButton{
    if (!_sendButton) {
        _sendButton = ({
            UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(40 * [UIScreen zj_screenWScale], self.phoneNumber.bottom + 80 * [UIScreen zj_screenHScale], self.view.width - 80 * [UIScreen zj_screenWScale], 50 * [UIScreen zj_screenHScale])];
            [button setTitle:@"提交" forState:UIControlStateNormal];
            [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            button.titleLabel.textAlignment = NSTextAlignmentCenter;
            button.titleLabel.font = LYPFONT(15);
            button.backgroundColor = [UIColor themeColor];
            [button addTarget:self action:@selector(clickButton) forControlEvents:UIControlEventTouchUpInside];
            button.layer.cornerRadius = 3;
            button.layer.masksToBounds = YES;
            button;
            
        });
    }
    return _sendButton;
}

- (UIScrollView *)backScrollView{
    if (!_backScrollView) {
        _backScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, LP_TopHeight, self.view.width, self.view.height - LP_TopHeight )];
        _backScrollView.contentOffset = CGPointMake(0, 0);
        _backScrollView.showsVerticalScrollIndicator = NO;
    }
    return _backScrollView;
    
}

@end
